/*   Carina
 *   Copyright (C) 2009 2010 2011  Zdravko Velinov
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef CARINA_EDITOR_HH
#define CARINA_EDITOR_HH

#include <QMainWindow>
#include <QSignalMapper>

#include "ui_editor.h"
#include "ces-converter.hh"
#include "property-editor.hh"
#include "scene-explorer.hh"
#include "entity-inspector.hh"

#include "carina/axis.hh"
#include "carina/common/timer.hh"
#include "carina/terrain.hh"
#include "carina/resources.hh"
#include "carina/lighting.hh"
#include "carina/common/memory.hh"
#include "carina/world-manager.hh"
#include "carina/node-manager.hh"
#undef Bool

using namespace Carina;

class CarinaEditor: public QMainWindow
{
    Q_OBJECT

    Ui::CarinaEditorWindow m_CEdWindow;

    typedef std::unordered_map<string, CESConverterPtr> CESConverterMap;
    CESConverterMap        m_Converters;

    CESFile                m_CurrentFile;
    string                 m_FileName;

    SceneExplorer          *m_SceneExp;
    PropertyEditor         *m_PropEdit;
    EntityInspector        *m_EntInsp;

    Timer                  m_Timer;

    RendererPtr            m_Renderer;

    ResourceManagerPtr     m_ResMgr;
    NodeManagerPtr         m_NodeMgr;
    LightingManagerPtr     m_Lighting;
    WorldManagerPtr        m_World;
    ScenePtr               m_Scene;

    AxisUPtr               m_Axis;

    enum {
        M_STAY     = 0,
        M_FORWARD  = 1,
        M_BACKWARD = 1 << 1,
        M_RIGHT    = 1 << 2,
        M_LEFT     = 1 << 3
    };

    bool                   m_Rotate;
    float                  m_Velocity;
    int                    m_Movement;
public:
    CarinaEditor();
     ~CarinaEditor();

private slots:
    void on_action_New_triggered(bool checked);
    void on_action_Open_triggered(bool checked);
    void on_action_Save_triggered(bool checked);
    void on_actionSave_As_triggered(bool checked);
    void on_action_Quit_triggered(bool checked);
    void on_actionAbout_Carina_Editor_triggered(bool checked);

    void on_action_CreateLightSource_triggered(bool checked);

    void on_CEView_resized(size_t x, size_t y);
    void on_CEView_rendering();
    void on_CEView_keyDown(int key);
    void on_CEView_keyUp(int key);
    void on_CEView_mousePressed(int button);
    void on_CEView_mouseReleased(int button);
    void on_CEView_mouseMoved(int x, int y, int xrel, int yrel);
};

#endif
